<?php

if(@$_GET['mode']){
			
	$arrExistLans = getExistLans();
	
	if($_GET['mode'] == "itags"){
		#This mode is to insert imported tags into database

		$id = "";
		$name = "";
		$parent = "";
		$section = "";
		$sort = "";
		$created = date("Y-m-d H:i:s",time());
		$path = "";
		$layerdepth = 0;
		$siteparent = "";
		$sitesort = 0;
		$accesstype = 0;
		$statustype =0;
		$module = "";
		
		if(@$_GET['id'])	
			$id = $_GET['id'];
		
		if(@$_GET['name'])
			$name = $_GET['name'];
		
		if(@$_GET['parent'])	
			$parent = $_GET['parent'];
		
		if(@$_GET['section'])
			$section = $_GET['section'];
	
		if(@$_GET['sort'])
			$sort = $_GET['sort'];
	
		if(@$_GET['xpath'])	
			$path = $_GET['xpath'];
		
		if(@$_GET['layerdepth'])
			$layerdepth = $_GET['layerdepth'];
		
		if(@$_GET['siteparent'])
			$siteparent = $_GET['siteparent'];
		
		if(@$_GET['sitesort'])
			$sitesort = $_GET['sitesort'];
		
		if(@$_GET['accesstype'])
			$accesstype = $_GET['accesstype'];
		
		if(@$_GET['statustype'])
			$statustype = $_GET['statustype'];
			
		if(@$_GET['xmlmodule'])
			$module = $_GET['xmlmodule'];
		
		if(count($arrExistLans) > 1){
					
			foreach($arrExistLans as $valueExistLans){
			
				$lan_id =  $valueExistLans['x_language']."(".$id.")";
				
				$lan_parent ="";
				
				if($parent != ""){
				
					$lan_parent = $valueExistLans['x_language']."(".$parent.")";
				}
				
				$lan_siteparent = "";
				
				if($siteparent != ""){
					
					$lan_siteparent = $valueExistLans['x_language']."(".$siteparent.")";
				}

				if($valueExistLans['x_language'] != "en"){
					
					$sql = "INSERT INTO ".$PROJECT_DB_TABLES["tags"]." (x_id,x_module,x_name,x_parent,x_accesstype,x_access,x_created,x_statustype,x_status,x_section,x_sort,x_language,x_path,x_depth,x_siteparent,x_sitesort) VALUES ('".$lan_id."','".$module."','".$name."','".$lan_parent."','".$accesstype."','2,3,".					
					getGroupIDByName($valueExistLans['x_language'])."','".$created."','".$statustype."',1,'".$section."',".$sort.",'".$valueExistLans['x_language']."','".$path."',".$layerdepth.",'".$lan_siteparent."','".$sitesort."')";//hash("md5",$id)
				}
				else if($valueExistLans['x_language'] == "en"){
					
					$sql = "INSERT INTO ".$PROJECT_DB_TABLES["tags"]." (x_id,x_module,x_name,x_parent,x_accesstype,x_access,x_created,x_statustype,x_status,x_section,x_sort,x_language,x_path,x_depth,x_siteparent,x_sitesort) VALUES ('".$lan_id."','".$module."','".$name."','".$lan_parent."','".$accesstype."','2,3','".$created."','".$statustype."',4,'".$section."',".$sort.",'".$valueExistLans['x_language']."','".$path."',".$layerdepth.",'".$lan_siteparent."','".$sitesort."')";//hash("md5",$id)
				}
				
				if(executeSQLQuery($sql))
					addContent("Successfully Insert ".$name."==".$module."<br/>");

				else	
					addContent("Insert fail:".$name."<br/>");

			}
		}
		else if(count($arrExistLans) == 0 || count($arrExistLans) == 1){
			
			  $en_id =  "en(".$id.")";
			  
			  $en_parent ="";
			  
			  if($parent != ""){
			  
				  $en_parent = "en(".$parent.")";
			  }
			  
			  $en_siteparent ="";
			  if($siteparent != ""){
					
					$en_siteparent = "en(".$siteparent.")";
			  }
			  
			  $sql = "INSERT INTO ".$PROJECT_DB_TABLES["tags"]." (x_id,x_module,x_name,x_parent,x_accesstype,x_access,x_created,x_statustype,x_status,x_section,x_sort,x_language,x_path,x_depth,x_siteparent,x_sitesort) VALUES ('".$en_id."','".$module."','".$name."','".$en_parent."','".$accesstype."','2,3','".$created."','".$statustype."',4,'".$section."',".$sort.",'en','".$path."',".$layerdepth.",'".$en_siteparent."','".$sitesort."')";//hash("md5",$id)
			  
			  if(executeSQLQuery($sql))			
			  	addContent("Successfully Insert ".$name."==".$module."<br/>");
			  else	
			  	addContent("Insert fail:".$name."<br/>");
		}
		
		//addContent($_GET['id']);
	}
	else if($_GET['mode'] == "iatt"){
		
		$id = "";
		$name = "";
		$value = "";
		$section = "";
		$module = "";
		
		if(@$_GET['id']){
			
			$id = $_GET['id'];
		}
		if(@$_GET['name']){
			
			$name = $_GET['name'];
		}
		if(@$_GET['value']){
			
			$value = $_GET['value'];
		}
		if(@$_GET['section']){
			
			$section = $_GET['section'];
		}
		if(@$_GET['xmlmodule'])
			$module = $_GET['xmlmodule'];
		
		if(count($arrExistLans) > 1){	
				
			foreach($arrExistLans as $valueExistLans){
			
				$lan_id =  $valueExistLans['x_language']."(".$id.")";
				
				$sql = "INSERT INTO ".$PROJECT_DB_TABLES["atri"]." (at_id,at_xml_id,at_name,at_value,at_section,at_language,at_module) VALUES ('".$lan_id.$name."','".$lan_id."','".$name."','".$value."','".$section."','".$valueExistLans['x_language']."','".$module."')";
				
				if(executeSQLQuery($sql))
					addContent("Successfully insert new attributes:".$name."<br/>");
				else
					addContent("Insert new attributes fail:".$name."<br/>");
			}
		}
		else if(count($arrExistLans) == 0 || count($arrExistLans) == 1){
			
			$en_id =  "en(".$id.")";
				
			$sql = "INSERT INTO ".$PROJECT_DB_TABLES["atri"]." (at_id,at_xml_id,at_name,at_value,at_section,at_language,at_module) VALUES ('".$en_id.$name."','".$en_id ."','".$name."','".$value."','".$section."','en','".$module."')";
			
			if(executeSQLQuery($sql))
				addContent("Successfully insert new attributes:".$name."<br/>");
			else
				addContent("Insert new attributes fail:".$name."<br/>");
		}
	
	}
	else if($_GET['mode'] == "ucon"){
		
		$id = "";
		
		$content = "";
		
		if(@$_GET['id']){
			
			$id = $_GET['id'];
		}
		
		if(@$_GET['content']){
			
			$content = $_GET['content'];
		}
		
		if(count($arrExistLans) > 1){	
		
			foreach($arrExistLans as $valueExistLans){
				
				$lan_id =  $valueExistLans['x_language']."(".$id.")";
				
				$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_content=\"".$content."\" WHERE x_id = \"".$lan_id."\"";
				
				if(executeSQLQuery($sql))				
					addContent("Content Updated!!<br/>");
				else	
					addContent("Content Update File fail!<br/>");
			}
		}
		else if(count($arrExistLans) == 1 || count($arrExistLans) == 0){
			
			$en_id =  "en(".$id.")";
				
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_content=\"".$content."\" WHERE x_id = \"".$en_id."\"";
				
			if(executeSQLQuery($sql))				
				addContent("Content Updated!!<br/>");
			else	
				addContent("Content Update File fail!<br/>");
		}
		/*<script type=\"text/javascript\">var objdiv= document.getElementById('dvLoadingZone');objdiv.scrollTop = objdiv.scrollHeight;</script>*/
	}
}

?>